﻿namespace System {
	class PrimitiveMethods {
		method listAdd(item) {
			@system_primitivemethods_listadd(item);
		}

		method listClear() {
			@system_primitivemethods_listclear;
		}

		method mapGet(key, defaultValue=null) {
			return @system_primitivemethods_mapget(key, defaultValue);
		}

		method mapContains(key) {
			return @system_primitivemethods_mapcontains(key);
		}

		method listAddList(list) {
			argmatch(LIST) {
				return @system_primitivemethods_listaddlist;
			} else {
				throw new InvalidArgumentException();
			}
		}

		method listInsert(index, value) {
			argmatch(INT, ANYTHING) {
				@system_primitivemethods_listinsert;
			} else {
				throw new InvalidArgumentException();
			}
		}

		method listRemove(index) {
			argmatch(INT) {
				@system_primitivemethods_listremove;
			} else {
				throw new InvalidArgumentException();
			}
		}

		method listReverse() {
			@system_primitivemethods_listreverse;
		}

		method mapAdd(key, value) {
			@system_primitivemethods_mapadd;
		}

		method mapClear() {
			@system_primitivemethods_mapclear;
		}

		method listJoin(delimiter="") {
			argmatch(STRING) {
				@system_primitivemethods_listjoin;
			} else {
				throw new InvalidArgumentException();
			}
		}

		method stringSplit(delimiter=null) {
			argmatch(STRING) {
				if (delimiter == '') {
					throw new InvalidArgumentException();
				}
				return @system_primitivemethods_stringsplit;
			} else argmatch(NULL) {
				return @system_primitivemethods_stringsplitwhitespace;
			} else {
				throw new InvalidArgumentException();
			}
		}

		method stringTrim(chars=null) {
			argmatch(NULL) {
				return @system_primitivemethods_stringtrim;
			} else argmatch(STRING) {
				return @system_primitivemethods_stringtrimchars;
			} else {
				throw new InvalidArgumentException();
			}
		}
	}
}